<?php
 if(isset($_POST['btn'])){
     if(!is_numeric($_POST['one']) || !is_numeric($_POST['one'])){
         echo "请输入数字";
     }else{
         $num=$_POST['num'];
         switch($num){
            case 1:
                $end=$_POST['one']+$_POST['two'];
                break;
            case 2:
                $end=$_POST['one']-$_POST['two'];
                break;
            case 3:
                $end=$_POST['one']*$_POST['two'];
                break;
            case 4:
                if($_POST['two']!=0){
                    $end=$_POST['one']/$_POST['two'];
                }else{
                    echo "分母不能为0";
                    $end='';
                }
                break;
            default:
                $end='';
                break;
         }
        echo <<< str
     <script>
       window.onload=function(){
       document.getElementById('end').value='$end'
      }
     </script>
     str;
     }
     
 }



?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="" method="POST">
    <input type="text" name="one">
    <select name="num" id="">
      <option value="0">请选择</option>
      <option value="1">+</option>
      <option value="2">-</option>
      <option value="3">*</option>
      <option value="4">/</option>
    </select>
    <input type="text" name="two">
    <input type="submit" value="计算" name="btn">
    <input type="text" name="end" id="end">
    </form>
</body>
</html>